﻿$(function ()
{
    $('#tt').datagrid({
        loadMsg: "Load Data...",
        iconCls: 'icon-reload',
        url: '',
        idField: 'UserID',
        hight: document.documentElement.clientHeight - 60,
        autoRowHeight: false,   // 自动行高（可能导致行高不一致）
        fitColumns: false,      // 不自动适应列宽（需要手动设置列宽）
        scrollbarSize: 18,       // 滚动条宽度设为0（可能影响布局）
        pageSize: 20,           // 每页20条
        striped: true,          // 隔行变色
        singleSelect: false,     // 单选模式
        pagination: true,       // 显示分页
        rownumbers: true,        // 显示行号
        sortable: true,
        columns: [[
            { field: 'UserID', checkbox: true },
            { field: 'UserNO', title: 'User Account', sortable: true, width: 150 },
            { field: 'UserName', title: 'UserName', width: 150 },
            { field: 'RStateName', title: 'Record State', width: 150 },
            { field: 'RegDate', title: 'Regist Date', width: 150 },
            { field: 'LastTime', title: 'Last Login', sortable: true, width: 150 },
            { field: 'CreateTime', title: 'CreateTime', width: 150 },
            { field: 'CreateUser', title: 'CreateUser', width: 150 },
            { field: 'UpdateTime', title: 'UpdateTime',  width: 150 },
            { field: 'UpdateUser', title: 'UpdateUser',  width: 150 },
            { field: 'RState',hidden:true}
        ]],
        onLoadSuccess: function (data) {
            $('#tt').datagrid("fillRows");
            $('#tt').datagrid('resize');
        },
        onSortColumn: function (order, sort) {
            $("#hSort").val(sort);
            $("#hOrder").val(order);
            /*      loadLocal();*/
        },
        onDblClickRow: function (index, row) {
            if (row == null) {
                Alert("Please Select One Row");
                return false;
            }
            $('#hUserID').val(row.UserID);
            $("#txtUserNO").textbox('setValue', row.UserNO);
            $("#txtUserName").textbox('setValue', row.UserName);
            $('#txtUserNO').textbox('disable');



            $('#dd').drawer('expand');

        }
    });
    $(window).resize(function () {
        $('#tt').datagrid('resize');
    });
    $('#dd').drawer({
        onCollapse: function () {
  
        },
        onExpand: function () {
            $(this).panel('panel').css('z-index', 9999);
        }
    });
});
function Search()
{
    var UserNO = $("#qUserNO").val();
    var UserName = $("#qUserName").val();
    var sort = $("#hSort").val();
    var order = $("#hOrder").val();

    $("#tt").datagrid({
        url: '../../api/SYS/QueryUserInfo',
        method: 'Get',
        queryParams: {
            UserNO: UserNO,
            UserName: UserName,
            sort: sort,
            order: order
        },
        loadFilter: function (data) {
            if (data.d) {
                return data.d;
            } else {
                return JSON.parse(data);
            }

        }
    });
    $('#tt').datagrid('unselectAll');
   

}
function AddNew() {

    $('#hUserID').val();
   // $('#txtUserNO').textbox('disable');

    // 启用文本框
    $('#txtUserNO').textbox('enable');
    $("#txtUserNO").textbox('setValue', "");
    $("#txtUserName").textbox('setValue', "");
    $('#dd').drawer('expand');
}
function Reset() {

    var Rows = $('#tt').datagrid('getSelections');
    if (Rows.length < 1) {
        alert("Please Select One or move Rows");
        return;
    }
    var jsonData = JSON.stringify(Rows);

    var url = '../../api/SYS/ResetUserInfo';
    DataService.PostJson(url, jsonData, function (res) {


        Notice(res.Message);
        Search();


    });
}
function Pause() {
    var Rows = $('#tt').datagrid('getSelections');
    if (Rows.length < 1) {
        alert("Please Select One or move Rows");
        return;
    }
    var jsonData = JSON.stringify(Rows);
  
    var url = '../../api/SYS/PauseUserInfo';
    DataService.PostJson(url, jsonData, function (res) {


        Notice(res.Message);
        Search();


    });
}
function Approve()
{
    var Rows = $('#tt').datagrid('getSelections');
    if (Rows.length < 1) {
        alert("Please Select One or move Rows");
        return;
    }

    var jsonData =JSON.stringify(Rows);

    var url = '../../api/SYS/ApproveUserInfo';
    DataService.PostJson(url, jsonData, function (res) {


        Notice(res.Message);
        Search();

       
    });
}
function Save() {
    if (!validateForm()) {
        return;
    }
    var UserID = $('#hUserID').val();
    var UserNO = $("#txtUserNO").textbox('getValue') ;
    var UserName = $("#txtUserName").textbox('getValue');
    var Info = {
        UserID: UserID,
        UserNO: UserNO,
        UserName: UserName
    }

    var url = '../../api/SYS/SaveUserInfo';
    DataService.AjaxPost(url, Info, function (res) {
        Notice(res.Message);

        Search();
        $('#dd').drawer('close');
      
     


    });
}